package com.lzc.lblog.lblog.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzc.lblog.lblog.entity.MPost;
import com.lzc.lblog.lblog.service.MPostService;
import com.lzc.lblog.lblog.vo.PostVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 首页控制器
 */
@Controller
public class IndexController extends BaseController{

    /**
     * 跳转到首页
     * @return
     */
    @RequestMapping({"index","","/"})
    public String index(@RequestParam(value = "pn",defaultValue = "1")Long pn,@RequestParam(value = "size",defaultValue = "2")Long size){
        Page page = new Page(pn,size);
        //分页查询 条件：分页条件 分类id 置顶 是否精华 用户 排序 状态 查询全部
        IPage<PostVo> voIPage=mPostService.paging(page,null,null,null,null,"created",null);
        req.setAttribute("result",voIPage);
        //本周热议
        List<MPost> mPostList=mPostService.hotsOnWeek();
        req.setAttribute("mPostList",mPostList);
        req.setAttribute("cid",0);
        return "index";
    }

    
}
